'use strict';

var path = require('path');

var express = require('express'),
	app = express(),
    router = express.Router(),
	config = require('./config');

app.use(express.static(path.join(__dirname,'dist')));

app.set('views', config.viewPath);
app.engine('.html', require('ejs').renderFile);
app.set('view engine', '.html');

app.use('/', router);

function render(res,req,title){
    title = req.query.title || title || '小忐忑';

    res.render('index',{
        title:title
    });
}

app.get('*', function(req, res) {
      render(res,req);
});

router.get('/version',function(req,res){
    res.sendFile('./version.txt',function(err){
        if (err) {
          console.log(err);
          res.status(err.status).end(err);
        }
    });
});
router.get('/MP_verify_j8L38JbSuxQTDt7B.txt',function(req,res){
    res.send('j8L38JbSuxQTDt7B');
});

app.listen(config.port,'0.0.0.0', function(err) {
	if(err) console.log(err)
	console.log('一致·心理 app server listening on port ' + config.port);
});
